package main

import (
	"context"
	"fmt"
	"go-study/global"
	"go-study/initialize"
	"go-study/model"
)

func main() {

	global.ASW_DB = initialize.Gorm()
	if global.ASW_DB != nil {
		initialize.RegisterTables()
		db, _ := global.ASW_DB.DB()
		defer db.Close()
	}

	u1 := model.User{
		Username: "zhangsan",
		Password: "123456",
		NickName: "张三",
	}
	global.ASW_DB.Create(&u1)
	userInfo := new(model.User)
	global.ASW_DB.First(&userInfo, "username = ?", "zhangsan")
	fmt.Println(userInfo)

	var ctx = context.Background()

	initialize.Redis()
	// expire 默认是 ns， 1s= 1000 000 000 ns
	err := global.ASW_REDIS.Set(ctx, "abc", 100, 0).Err()
	val, err := global.ASW_REDIS.Get(ctx, "abc").Result()
	fmt.Println(val, err)

	if err != nil {
		fmt.Println(err)
	}
	//core.RunWindowsServer()
}
